<template>
  <div class="container flow-column h100">
    <div class="container-main h100">
      <list-table-new v-bind="tableSetting" ref="tableRef"></list-table-new>
    </div>
  </div>
</template>
<script>
import { getSampleTicketList } from "@/api/twoTicketManagement/workTicket.js";
export default {
  data() {
    return {
      tableSetting: {
        singleRow: true,
        radioShow: true,
        showCustomBtn: true, //显示自定义列
        showFilterBtn: true, //显示过滤器
        // 搜索框
        searchObj: {
          searchMethod: (params, sortStr) => {
            this.getTableData(params, sortStr);
          },
          queryData: {
            page: 1,
            pageSize: 15,
          },
          searchArr: [
            {
              type: "select",
              label: "工作票类型",
              model: "type",
              option: this.$store.getters["dirtData"]("ticket_work_type"),
            },
            {
              type: "input",
              label: "标题",
              model: "title",
              placeholder: "请输入",
            },
            {
              type: "organization",
              label: "创建单位",
              model: "deptName",
              // idsStr: "deptId",
              placeholder: "请选择或输入",
            },
            {
              type: "userOnly",
              label: "创建人",
              model: "createByName",
              // idsStr: "createBy",
              placeholder: "请选择或输入",
            },
            {
              type: "datetimerange",
              label: "创建时间",
              model: "createTime",
            },
          ],
        },
        // 表头
        column: [
          {
            label: "工作票类型",
            prop: "type",
            formatter: (row) => {
              let types = this.$store.getters["dirtData"]("ticket_work_type");
              let val = row.type;
              let obj = types.find((i) => i.value == val);
              return obj ? obj.label : val;
            },
          },
          {
            label: "标题",
            prop: "title",
          },
          {
            label: "创建单位",
            prop: "deptName",
          },
          {
            label: "创建人",
            prop: "createBy",
          },
          {
            label: "创建时间",
            prop: "createTime",
          },
        ],
        // 表格方法
        tableMethods: {
          //点击行的方法
          rowClick: (val) => {
            this.$refs.tableRef.radioSelect(val);
          },
        },
      },
    };
  },
  created() {
    // let query = {
    //   // deptId: this.$store.state.user.userInfo.orgId || this.$store.state.user.userInfo.deptId,
    //   deptName:
    //     this.$store.state.user.userInfo.orgName ||
    //     this.$store.state.user.userInfo.deptName,
    // };
    // this.tableSetting.searchObj.queryData = Object.assign(
    //   this.tableSetting.searchObj.queryData,
    //   query
    // );
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.$refs.tableRef.searchData();
    },
    // 查询表格数据
    async getTableData(params, sortStr) {
      let queryData = Object.assign({}, params);
      // if (sortStr.length > 0) {
      //   queryData.orders = sortStr;
      // }
      if (queryData.createTime) {
        queryData.startCreateTime = queryData.createTime[0];
        queryData.endCreateTime = queryData.createTime[1];
        delete queryData.createTime;
      }
      getSampleTicketList(queryData)
        .then((list) => {
          this.$set(this.tableSetting, "tableData", list.data.list);
          this.$set(this.tableSetting, "totalNumber", list.data.total);
        })
        .catch((e) => {
          this.$set(this.tableSetting, "tableData", []);
          this.$set(this.tableSetting, "totalNumber", 0);
        });
    },
    // 返回选中数据
    getSelectData() {
      let val = this.$refs.tableRef.getRadioData();
      let selectData = val ? { id: val.id, type: val.type } : null;
      return selectData;
    },
  },
};
</script>
<style lang="less" scoped>
.container {
  .container-main {
    // margin-left: 10px;
  }
}
.flow-column {
  display: flex;
  flex-flow: column nowrap;
}
</style>